﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SoucreGame.GLO;


namespace SoucreGame.GUI
{
    class guiCaiDat
    {
        
        Texture2D guiManHinhNen; // hinh anh lam nen
        Texture2D guiCaidat;
        Texture2D cmdNutAmLuong;
        Texture2D cmdNutNhacNen;
        Texture2D cmdNutAmThanh;
        Texture2D cmdNutThoat;
        

        Dictionary<string, Rectangle> dsToaDoGiaoDien;
        ContentManager content;
        GameTime gameTime;
        SpriteBatch spriteBatch;

        public guiCaiDat(ContentManager _content, GameTime _gameTime, SpriteBatch _spritBatch)
        {
            content = _content;
            gameTime = _gameTime;
            spriteBatch = _spritBatch;

            if (content != null)
            {
                guiManHinhNen = content.Load<Texture2D>("GUII\\guiManHinhNen");
                guiCaidat = content.Load<Texture2D>("GUII\\guiCaiDat");
                cmdNutAmLuong = content.Load<Texture2D>("GUII\\cmdNutAmLuong");
                cmdNutNhacNen = content.Load<Texture2D>("GUII\\cmdNutNhacNen");
                cmdNutAmThanh = content.Load<Texture2D>("GUII\\cmdNutAmThanh");
                cmdNutThoat = content.Load<Texture2D>("GUII\\cmdNutThoat");

                dsToaDoGiaoDien = content.Load<Dictionary<string, Rectangle>>("GUII\\guiViTri");
            }
        }

        public void Update(GameTime gameTime)
        {
            CGlobalvariable.trangthaitruoc = CGlobalvariable.trangthaihientai;
            CGlobalvariable.trangthaihientai = Mouse.GetState();
            if (CGlobalvariable.trangthaihientai.LeftButton == ButtonState.Pressed && CGlobalvariable.trangthaitruoc.LeftButton == ButtonState.Released)
            {
                if (dsToaDoGiaoDien["cmdNutAmLuong"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiAmLuong;
                }

                else if (dsToaDoGiaoDien["cmdNutAmThanh"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiAmThanh;
                }

                else if (dsToaDoGiaoDien["cmdNutNhacNen"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiManHinhNhacNen;
                }

                else if (dsToaDoGiaoDien["cmdNutThoat"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                {
                    CGlobalvariable.Chuyengiaodien = true;
                    CGlobalvariable.Giaodiendangchon = GUIEnum.guiLevel;
                }
            }
        }

        public void Draw(GameTime gameTime)
        {
            this.spriteBatch.Draw(guiManHinhNen, Vector2.Zero, Color.White);
            this.spriteBatch.Draw(guiCaidat, new Vector2(dsToaDoGiaoDien["guiCaiDat"].X, dsToaDoGiaoDien["guiCaiDat"].Y), Color.White);
            this.spriteBatch.Draw(cmdNutAmLuong, new Vector2(dsToaDoGiaoDien["cmdNutAmLuong"].X, dsToaDoGiaoDien["cmdNutAmLuong"].Y), Color.White);
            this.spriteBatch.Draw(cmdNutNhacNen, new Vector2(dsToaDoGiaoDien["cmdNutNhacNen"].X, dsToaDoGiaoDien["cmdNutNhacNen"].Y), Color.White);
            this.spriteBatch.Draw(cmdNutAmThanh, new Vector2(dsToaDoGiaoDien["cmdNutAmThanh"].X, dsToaDoGiaoDien["cmdNutAmThanh"].Y), Color.White);
            this.spriteBatch.Draw(cmdNutThoat, new Vector2(dsToaDoGiaoDien["cmdNutThoat"].X, dsToaDoGiaoDien["cmdNutThoat"].Y), Color.White);
        }
    }
}
